<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layouts/layout}">
<!-- BEGIN HEAD -->
<head>
    <title>短信模板列表</title>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
<th:block layout:fragment="content">
    <!-- BEGIN PAGE CONTAINER-->
    <div class="container-fluid">
        <!-- BEGIN PAGE HEADER-->
        <!-- END PAGE HEADER-->
        <!-- BEGIN PAGE CONTENT-->
        <div class="portlet-body form">
            <div class="row-fluid">
                <div class="span5">
                    <div class="control-group">
                        <div class="controls">
                            <input type="button" class="btn btn-sm btn-info green" onclick="add()" value="新建"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row-fluid">
            <!-- BEGIN SIDEBAR -->
            <div class="span12">
                <!-- BEGIN SAMPLE FORM PORTLET-->
                <div class="portlet">
                    <div class="portlet-body form">
                        <!-- BEGIN FORM-->
                        <table id="table"></table>
                    </div>
                </div>
                <!-- END SAMPLE FORM PORTLET-->
            </div>
        </div>
        <!-- END PAGE CONTENT-->
    </div>
    <!-- END PAGE CONTAINER-->
</th:block>
<th:block layout:fragment="content-js">
    <script type="text/javascript" th:src="@{/assets/js/dateConvert.js}"></script>
    <script th:inline="javascript">
        $(function () {
            initTable();
        });

        function initTable() {
            $("#table").bootstrapTable({
                dataType: "json",
                url: "/template/listPage",
                method: 'post',//必选
                contentType: 'application/x-www-form-urlencoded; charset=UTF-8',//编码,必选
                sidePagination: "server", //表格分页的位置,必选
                pagination: true, //启动分页
                pageSize: 10, //每页显示的记录数
                pageNumber: 1, //当前第几页
                pageList: [10, 20, 30], //记录数可选列表
                striped: true,
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                queryParams: queryParams,
                columns: [
                    {
                        field: 'id',
                        title: 'id',
                        align: 'center'
                    },
                    {
                        field: 'vendorId',
                        title: '商户Id',
                        align: 'center'
                    },
                    {
                        field: 'smsType',
                        title: '短信模板类型',
                        align: 'center'
                    },
                    {
                        field: 'content',
                        title: '内容',
                        align: 'center'
                    },
                    {
                        field: 'updateTime',
                        title: '更新时间',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return changeDateFormat(value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return '<a href="/template/edit?id=' + row.id + '" > <i class="icon-edit icon-on-right">修改</i></a>';
                        }
                    }
                ],
                responseHandler: function (res) {
                    if (res.code === '0000') {
                        return {total: res.data.total, rows: res.data.records}
                    } else {
                        bootbox.alert(res.msg);
                        return {};
                    }
                }
            })
        }

        // 查询条件
        function queryParams(params) {
            return params;
        }

        function search() {
            $('#table').bootstrapTable('refresh');
        }

        function add() {
            window.location.href = "/template/add";
        }
    </script>

</th:block>
</body>
<!-- END BODY -->
</html>